<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class ShopController extends Controller
{
	//显示购物车视图
	public function shopIndex(){
		//查询数据
		$result=DB::table('shop')
		->join('userdetail','userdetail.did','=','shop.did')
		->join('goods','goods.gid','=','shop.gid')
		->join('uclassify','uclassify.cid','=','shop.cid')
		->select('userdetail.dname','shop.*','uclassify.cname','goods.gname','goods.cid','goods.gmoney')
		->get();

		return view('/shop/adminShop',['result'=>$result]);
	}
	
	//购物车的修改模板
	public function shopUpdate($sid){
		//查询数据
		$result=DB::table('shop')
		->join('goods','goods.gid','=','shop.gid')
		->join('userdetail','userdetail.did','=','shop.did')
		->join('uclassify','uclassify.cid','=','shop.cid')
		->where('sid','=',$sid)
		->first();
		//dd($result);
		//$cid=$result->cid;
		//$result1=DB::table('uclassify')->where('cid','=',$cid)->first();,'result1'=>$result1->cname
		return view('/shop/shopUpdate',['result'=>$result]);
	}	
	//购物车的修改操作
	public function shopUpdatea(Request $request){
		//接收表单传递过来的值
		$result=$request->only('scolor','scm');
		$result1=$request->only('sid');
		$sid=$result1['sid'];
		//修改数据
		$res=DB::table('shop')->where('sid','=',$sid)->update($result);
		//判断结果
		if($res){
			return redirect('/shop/index');
		}else{
			return redirect("/shop/shopUpdate/{$sid}");
		}
	}
	//购物车的删除模板
	public function shopDelete($sid){
		//根据sid删除数据
		$result=DB::table('shop')->where('sid','=',$sid)->delete();
		//判断结果
		if($result){
			return redirect('/shop/index');
		}else{
			return redirect('/shop/index');
		}
	}
	
}
